<?php
/**
 * 会员注册
 *
 *
 * @copyright  Copyright (c) 2007-2013 ShopNC Inc. (http://www.shopnc.net)
 * @license    http://www.shopnc.net
 * @link       http://www.shopnc.net
 * @since      File available since Release v1.1
 */
defined('InShopNC') or exit('Access Invalid!');

class registerControl extends MobileControl {

	public function __construct(){
		parent::__construct();
	}
	
	public function indexOp(){
		//实例化模型
		$model_member	=new memberModel();
		//检查登录状态
		$model_member->checkloginMember();
		//注册提交
		if(chksubmit()){
			//重复注册验证
			if (check_repeat('reg',30)){
				mobileJump('您的操作过于频繁，请稍后再试','index.php');
			}
			// 注册验证
			$obj_validate = new Validate();
			$obj_validate->validateparam = array(
				array("input"=>$_POST["user_name"],		"require"=>"true",		"message"=>'用户名不能为空'),
				array("input"=>$_POST["code"],"require"=>"true","message"=>'邀请码不能为空'),
				array("input"=>$_POST["password"],	"require"=>"true","message"=>'密码不能为空'),
				array("input"=>$_POST["password_confirm"],"require"=>"true","validator"=>"Compare","operator"=>"==","to"=>$_POST["password"],"message"=>'确认密码与密码不一致'),
				array("input"=>strtoupper($_POST["captcha"]),"require"=>(C('captcha_status_register') == '1' ? "true" : "false"),"message"=>'验证码不能为空'),
				array("input"=>$_POST["province_id"],	"require"=>"true", "message"=>'请选择省份'),
				array("input"=>$_POST["city_id"],	"require"=>"true", "message"=>'请选择城市'),
				array("input"=>$_POST["area_id"],	"require"=>"true", "message"=>'请选择地区'),
                array("input"=>$_POST["mobile"],	"require"=>"true", "message"=>'请输入手机号码'),
                array("input"=>$_POST["mobileCode"],	"require"=>"true", "message"=>'请输入短信验证码'),
				array("input"=>$_POST["agree"],"require"=>"true", "message"=>'您必须同意服务协议才能注册'),
			);
			$error = $obj_validate->validate();
			if ($error != ''){
				mobileJump($error);
			}
			if (C('captcha_status_register')){
				if (!checkSeccode($_POST['nchash'],$_POST['captcha'])){
					mobileJump('验证码错误');
				}
			}
			$check_member_name	= $model_member->infoMember(array('member_name'=>trim($_POST['user_name'])));
			if(is_array($check_member_name) and count($check_member_name)>0) {
				mobileJump('您填写的用户名称已经存在，请您选择其他用户名填写');
			}
            $user_array	= array();
            $check_member_mobile	= $model_member->infoMember(array('member_mobile'=>trim($_POST['mobile'])));
            if(is_array($check_member_mobile) and count($check_member_mobile)>0) {
                mobileJump('手机号码已存在');
            }
            $sql = "SELECT * FROM #__member_mobile_validation WHERE valid_id = '{$_SESSION['mobile_valid_id']}'";
            $mobile_valid_info = Db::queryRow($sql);
            if($mobile_valid_info['valid_mobile'] != $_POST["mobile"]){
                mobileJump('提交的手机号码与验证手机号码不一致');
            }
            $user_array['member_mobile'] = $_POST["mobile"];
            $nowTime = time();
            //核对验证码期限
            if($nowTime > ($mobile_valid_info['send_time']+(MOBILE_VALID_ACTIVE_TERM * 60))){
                mobileJump('该短信验证码已过有效期，请重新获取！');
            }
            if($mobile_valid_info['send_code'] != md5($_POST["mobileCode"])){
               mobileJump('短信验证码错误');
            }
			$code = trim($_POST['code']);
			//查询该邀请码是否已使用
			$sql = "SELECT * FROM #__member WHERE InvitationCode = '$code'";
			$m_rs = Db::queryRow($sql);
			if(!empty($m_rs) && is_array($m_rs)){
				mobileJump('该邀请码已经使用');
			}else{
				//查询是否存在该邀请码
				$sql = "SELECT * FROM #__ams_store WHERE invitation_code = '$code'";
				$a_rs = Db::queryRow($sql);
				if(!empty($a_rs) && is_array($a_rs)){
					$user_array['InvitationCode'] = $code;
					//查询商城名称是否有重复
					/*$sql = "SELECT * FROM #__member WHERE member_name = '{$a_rs['store_name']}'";
					$n_rs = Db::queryRow($sql);
					if(!empty($n_rs) && is_array($n_rs)){
						$user_array['member_name'] = $this->create_random($a_rs['store_name']);
					}else{
						$user_array['member_name'] = $a_rs['store_name'];
					}*/
				}else{
					//查询是否存在该邀请码
					$sql = "SELECT * FROM #__ams_supplier WHERE invitation_code = '$code'";
					$s_rs = Db::queryRow($sql);
					if(!empty($s_rs) && is_array($s_rs)){
						$user_array['InvitationCode'] = $code;
						//查询商城名称是否有重复
						/*$sql = "SELECT * FROM #__member WHERE member_name = '{$s_rs['name']}'";
						$n_rs = Db::queryRow($sql);
						if(!empty($n_rs) && is_array($n_rs)){
							$user_array['member_name'] = $this->create_random($s_rs['name']);
						}else{
							$user_array['member_name'] = $s_rs['name'];
						}*/
					}else{
						mobileJump('该邀请码不存在');
					}
				}
			}

			/**
			 * 会员添加
			 */
			$user_array['member_name'] = trim($_POST['user_name']);
			$user_array['member_passwd']	= $_POST['password'];
			$user_array['member_state'] = '1';
			$user_array['member_provinceid'] = (int)$_POST['province_id'];
			$user_array['member_cityid'] = (int)$_POST['city_id'];
			$user_array['member_areaid'] = (int)$_POST['area_id'];
			//包含地区数组文件
			include BasePath.DS.'data/area/areaall.php';
			$area_info = $area_array[$_POST['province_id']]['area_name'];
			$area_info .= chr(9).$area_array[$_POST['city_id']]['area_name'];
			$area_info .= chr(9).$area_array[$_POST['area_id']]['area_name'];
			$user_array['member_areainfo'] = $area_info;
			$result	= $model_member->addMember($user_array);
			if($result) {
				//注册时间标记，访问灌入垃圾用户
				setNcCookie('rp_reg',time());
				$_SESSION['is_login']	= '1';
				$_SESSION['member_id']	= $result;
				$_SESSION['member_name']= trim($user_array['member_name']);
				$_SESSION['member_email']= trim($user_array['member_email']);
	
				$this->mergecart();						// cookie中的cart存入数据库
	
				//添加会员积分
				if ($GLOBALS['setting_config']['points_isuse'] == 1){
					$points_model =new pointsModel();
					$points_model->savePointsLog('regist',array('pl_memberid'=>$_SESSION['member_id'],'pl_membername'=>$_SESSION['member_name']),false);
				}
				mobileModel::send($_POST["mobile"], str_replace('site_name', C('site_name'), '你的账号是：' . $user_array ["member_name"] . ',请您牢记，方便下次登陆。欢迎来到site_name建议您尽快完善资料，祝您购物愉快!'));
                                 mobileJump('注册成功','index.php?act=member_index');
			} else {
				mobileJump('注册失败');
			}
		}
		if(C('captcha_status_register') == '1'){
			Tpl::output('nchash',substr(md5(SiteUrl.$_GET['act'].$_GET['op']),0,8));
		}
		//用户服务协议
		$model_doc	=new documentModel();
		$doc	= $model_doc->getOneByCode('agreement');
		Tpl::output('doc',$doc);
		
		Tpl::output('html_title',C('site_name').' - 会员注册');
		Tpl::output('title','邀请码注册');
		Tpl::output('code_reg',true);   //为邀请码注册

		Tpl::showpage('register');
	}
	
	public function no_code_shareOp() {
                $model_member	=new memberModel();
                $model_member->checkloginMember();
                if(chksubmit()){
                    if (check_repeat('reg',30)){
                        mobileJump('您的操作过于频繁，请稍后再试','index.php');
                    }
                    $obj_validate = new Validate();
                    $obj_validate->validateparam = array(
                            array(
                                "input"=>$_POST["regName"],
                                "require"=>"true",
                                "validator"=>"Custom",
                                //用户名可以为汉字.字母.数字-_.,汉字是一个字符
                                "regexp"=>"/^[\x{4e00}-\x{9fa5}\w]{3,20}$/u",
                                "message"=>'用户名为3~20个字符的汉字，字母，数字，下划线',
                            ),
                            array(
                                "input"=>$_POST["pwd"],
                                "require"=>"true",
                                "validator"=>"Custom",
                                "regexp"=>"/^\w{6,20}$/",
                                "message"=>"密码必须是6到20位的字母数字_"
                            ),
                            array(
                                "input" => $_POST ["pwdRepeat"],
                                "require" => "true",
                                "validator" => "Compare",
                                "operator" => "==",
                                "to" => $_POST ["pwd"],
                                "message" => "确认密码与密码必须一致"
                            ),
                            array(
                                "input" => $_POST ["mobile"],
                                "require" => "true",
                                "validator"=>"Custom",
                                "regexp"=>"/(^1[3578]\d{5}$)|(^1[3578]\d{9}$)/",
                                "message" => '手机号码不正确'
                            ),
                            array("input"=>$_POST["mobileCode"],
                                "require"=>"true",
                                "message"=>'短信验证码不能为空'
                            ),
                );

                $error = $obj_validate->validate();
                $error = explode('<br/>',$error);
                if ($error[0]!= ''){
                    mobileJump($error[0]);
                }
                $check_member_name	= $model_member->infoMember(array('member_name'=>trim($_POST['regName'])));
                if(is_array($check_member_name) and count($check_member_name)>0) {
                    mobileJump("该用户名已注册，请用别的用户名");
                }
                $check_member_mobile	= $model_member->infoMember(array('member_mobile'=>trim($_POST['mobile'])));
                if(is_array($check_member_mobile) and count($check_member_mobile)>0) {
                    mobileJump('手机号码已存在');
                }
                $sql = "SELECT * FROM #__member_mobile_validation WHERE valid_id = '{$_SESSION['mobile_valid_id']}'";
                $mobile_valid_info = Db::queryRow($sql);
                if($mobile_valid_info['valid_mobile'] != $_POST["mobile"]){
                    mobileJump('提交的手机号码与验证手机号码不一致');
                }
                $nowTime = time();
                //核对验证码期限
                if($nowTime > ($mobile_valid_info['send_time']+(MOBILE_VALID_ACTIVE_TERM * 60))){
                    mobileJump('该短信验证码已过有效期，请重新获取！');
                }
                if($mobile_valid_info['send_code'] != md5($_POST["mobileCode"])){
                    mobileJump('短信验证码错误');
                }
                if (C('captcha_status_register')==1){
                    if (!checkSeccode($_POST['nchash'],$_POST['captcha'])){
                        mobileJump('请输入正确的验证码');
                    }
                }

                $user_array	= array();
                /**
                 * 会员添加
                 */
                $user_array['member_name']		= $_POST['regName'];
                $user_array['member_passwd']	= $_POST['pwd'];
                $user_array['member_mobile']		= $_POST['mobile'];
                $user_array['member_state'] = '0';
                $user_array['member_provinceid'] = (int)$_POST['province_id'];
                $user_array['member_cityid'] = (int)$_POST['city_id'];
                $user_array['member_areaid'] = (int)$_POST['area_id'];
                //包含地区数组文件
                include BasePath.DS.'data/area/areaall.php';
                $area_info = $area_array[$_POST['province_id']]['area_name'];
                $area_info .= chr(9).$area_array[$_POST['city_id']]['area_name'];
                $area_info .= chr(9).$area_array[$_POST['area_id']]['area_name'];
                $user_array['member_areainfo'] = $area_info;
                $result	=  $member_id = $model_member->addMember($user_array);
                if($result) {
                    //处理邀请注册 
                    $invitcode = isset($_COOKIE['invitcode']) ? unserialize(base64_decode($_COOKIE['invitcode'])):'';
                    if(isset($invitcode['member_id']) && $invitcode['member_id'] > 0) {
                        $invitArr = array();
                        $invitArr['invite_type'] = '2';
                        $invitArr['invite_price'] = MEMBER_INVITES_PRICE;//邀请注册赠送金额
                        $invitArr['member_id'] = $invitcode['member_id'];
                        $invitArr['member_name'] = $invitcode['member_name'];
                        $invitArr['imember_id'] =  $member_id;
                        $invitArr['imember_name'] = $user_array ['member_name'];
                        $invitArr['ip'] =  getIp();
                        $invitArr['is_give'] = MEMBER_INVITES_IS_GIVE_NO;       // 等待审核后才给现金券
                        $invitArr['add_time'] = time();
                         Db::insert('member_invites', $invitArr);
                        unset($invitArr , $invitcode);
                        //删除cookie
                        setcookie("invitcode" , '' , time()-100, '/','d1mcw.com');
                    }
                    // 注册成功
                    mobileModel::send2($_POST ['mobile'],'【D1美财网】恭喜您：会员' . $_POST ['regName'] . '，您获得美财网送出的100元现金券一张，10天内使用面额为100元，10天后使用面额将变为50元，可选购精品超市海量商品，超低价，货到付款，还犹豫什么，快去挑选心仪的商品吧。现金券有效期' . date('m-d',time()) . ' - ' . date('m-d',time()+30*3600*24) . '。m.d1mcw.com');
                    mobileJump('恭喜您，您的账号：' . $_POST ['regName'] . ' 注册成功，为确保会员信息真实有效，您的账号已进入审核状态，客服人员48小时内会给您电话回访，请您保持电话畅通，耐心等待。','index.php');
                } else {
                    mobileJump('注册失败，请稍后尝试');
                }
            }
            if(C('captcha_status_register') == '1'){
                Tpl::output('nchash',substr(md5(SiteUrl.$_GET['act'].$_GET['op']),0,8));
            }
            //用户服务协议
            $model_doc	=new documentModel();
            $doc	= $model_doc->getOneByCode('agreement');
            Tpl::output('doc',$doc);
            Tpl::output('html_title',C('site_name').' - 会员注册');
            Tpl::showpage('no_code_share');
	}
    
        public function no_code_regOp() {
		$model_member	=new memberModel();
		$model_member->checkloginMember();
		if(chksubmit()){
			if (check_repeat('reg',30)){
				mobileJump('您的操作过于频繁，请稍后再试','index.php');
			}

			$obj_validate = new Validate();
			$obj_validate->validateparam = array(
                array(
                    "input"=>$_POST["regName"],
                    "require"=>"true",
                    "validator"=>"Custom",
                    //用户名可以为汉字.字母.数字-_.,汉字是一个字符
                    "regexp"=>"/^[\x{4e00}-\x{9fa5}\w-]{3,20}$/u",
                    "message"=>'用户名为3~20位的汉字/字母/数字/下划线',
                ),
                array(
                    "input"=>$_POST["pwd"],
                    "require"=>"true",
                    "validator"=>"Custom",
                    "regexp"=>"/^\w{6,20}$/",
                    "message"=>"密码为6~20位的字母/数字/常用符号"
                ),
                array(
                    "input" => $_POST ["pwdRepeat"],
                    "require" => "true",
                    "validator" => "Compare",
                    "operator" => "==",
                    "to" => $_POST ["pwd"],
                    "message" => "确认密码与密码必须一致"
                ),
                array(
                    "input" => $_POST ["mobile"],
                    "require" => "true",
                    "validator"=>"Custom",
                    "regexp"=>"/(^1[3578]\d{5}$)|(^1[3578]\d{9}$)/",
                    "message" => '手机号码不正确'
                ),
				array("input"=>$_POST["mobileCode"],
                    "require"=>"true",
                    "message"=>'短信验证码不能为空'
                ),
				/*array(
                    "input"=>$_POST["invite_name"],
                    "require"=>$this->mv_type('invite_name'),
                    "validator"=>"Custom",
                    //用户名可以为汉字.字母.数字-_.,汉字是一个字符
                    "regexp"=>"/^[\x{4e00}-\x{9fa5}\w]{3,20}$/u",
                    "message"=>'邀请会员不正确',
                ),*/
                array(
                    "input"=>$_FILES['member_idcard']['name'],
                    "require"=>$this->mv_type('identify_card'),
                    "message"=>'身份证正面照片不能为空'
                ),
                array(
                    "input"=>$_FILES['member_idcard_r']['name'],
                    "require"=>$this->mv_type('identify_card'),
                    "message"=>'身份证反面照片不能为空'
                ),
                array(
                    "input"=>$_FILES['member_inside_photo']['name'],
                    "require"=>$this->mv_type('identify_card'),
                    "message"=>'店内照片不能为空'
                ),
			);
			if($_POST['register_type']==1){
			$obj_validate->validateparam = array(
				array(
					"input"=>$_POST["invite_name"],
					"require"=>$this->mv_type('invite_name'),
					"validator"=>"Custom",
					//用户名可以为汉字.字母.数字-_.,汉字是一个字符
					"regexp"=>"/^[\x{4e00}-\x{9fa5}\w]{3,20}$/u",
					"message"=>'邀请会员不正确',
				),
			);}
			if(false&&$_POST['register_type']==2){
				$obj_validate->validateparam = array(
					array(
						"input"=>$_POST['member_bizlicense_url'],
						"require"=>$this->mv_type('member_bizlicense'),
						"message"=>'营业执照照片不能为空'
					),
				);
			}

			$error = $obj_validate->validate();
            $error = explode('<br/>',$error);
			if ($error[0]!= ''){
                mobileJump($error[0]);
			}
			$check_member_name	= $model_member->infoMember(array('member_name'=>trim($_POST['regName'])));
			if(is_array($check_member_name) and count($check_member_name)>0) {
				mobileJump("该用户名已注册，请用别的用户名");
			}
			$check_member_mobile	= $model_member->infoMember(array('member_mobile'=>trim($_POST['mobile'])));
			if(is_array($check_member_mobile) and count($check_member_mobile)>0) {
				mobileJump('手机号码已存在');
			}
            //如果是邀请会员注册方式，则要验证用户名是否存在，如果不存在，重新注册
            if($this->mv_type('invite_name')){
                $is_invite_name	= $model_member->infoMember(array('member_name'=>trim($_POST['invite_name']),'member_id'));
                if($is_invite_name==null) {
                    mobileJump("邀请会员不存在");
                }
            }
			$sql = "SELECT * FROM #__member_mobile_validation WHERE valid_id = '{$_SESSION['mobile_valid_id']}'";
			$mobile_valid_info = Db::queryRow($sql);
			if($mobile_valid_info['valid_mobile'] != $_POST["mobile"]){
				mobileJump('提交的手机号码与验证手机号码不一致');
			}
			$nowTime = time();
			//核对验证码期限
			if($nowTime > ($mobile_valid_info['send_time']+(MOBILE_VALID_ACTIVE_TERM * 60))){
				mobileJump('该短信验证码已过有效期，请重新获取！');
			}
			if($mobile_valid_info['send_code'] != md5($_POST["mobileCode"])){
				mobileJump('短信验证码错误');
			}
            if (C('captcha_status_register')==1){
                if (!checkSeccode($_POST['nchash'],$_POST['captcha'])){
                   // mobileJump('请输入正确的验证码');
                }
            }
			$upload = new UploadFile();
            //根据选择的注册方案来上传
            switch($_POST['mv_type']){
                case 'identify_card':
                    $idcard_path = ATTACH_MALBUM.DS.'idcard'.DS.date("Ym").DS;

                    //添加身份证反面文件夹
                    $idcard_rpath = ATTACH_MALBUM.DS.'idcard_r'.DS.date("Ym").DS;
                    $inside_photo_path = ATTACH_MALBUM.DS.'inside_photo'.DS.date("Ym").DS;
                    //身份证正面照片上传
                    $upload->set('default_dir',$idcard_path);
                    $upload->set('ifremove', false);
                    $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
                    $idcard = $upload->upfile('member_idcard');
                    if($idcard){
                        $member_idcard = $idcard_path.$upload->file_name;
                    }else{
                        mobileJump('身份证照片上传失败，允许上传图片类型为：jpg、jpeg、png、gif');
                    }
                    //身份证反面照片上传
                    $upload->set('default_dir',$idcard_rpath);
                    $upload->set('ifremove', false);
                    $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
                    $idcard_r = $upload->upfile('member_idcard_r');
                    if($idcard_r){
                        //如果上传成功，将图片路径保存
                        $member_idcard_r = $idcard_rpath.$upload->file_name;
                    }else{
                        unlink(BasePath.DS.$member_idcard);
                          mobileJump('身份证反面照片上传失败，允许上传图片类型为：jpg、jpeg、png、gif');
                    }
                    //店内照片上传
                    $upload->set('default_dir',$inside_photo_path);
                    $upload->set('ifremove', false);
                    $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
                    $inside_photo = $upload->upfile('member_inside_photo');
                    if($inside_photo){
                        $member_inside_photo = $inside_photo_path.$upload->file_name;
                    }else{
                        unlink(BasePath.DS.$member_idcard);
                        unlink(BasePath.DS.$member_idcard_r);
                        mobileJump('店内照片上传失败，允许上传图片类型为：jpg、jpeg、png、gif');
                    }
                break;

                default:
            }

			$user_array	= array();
			/**
			 * 会员添加
			 */
			$user_array['member_name']		= $_POST['regName'];
			$user_array['member_passwd']	= $_POST['pwd'];
			$user_array['member_mobile']		= $_POST['mobile'];
            if($this->mv_type('invite_name')){
                $user_array['invite_member']		= $_POST['invite_name'];
            }elseif($this->mv_type('identify_card')){
                $user_array['member_idcard']		= $member_idcard;
                $user_array['member_idcard_r']		= $member_idcard_r;
                $user_array['member_inside_photo']		= $member_inside_photo;
            }
			$user_array['member_state'] = '1';
            $user_array['member_provinceid'] = (int)$_POST['province_id'];
            $user_array['member_cityid'] = (int)$_POST['city_id'];
            $user_array['member_areaid'] = (int)$_POST['area_id'];
			$user_array['member_bizlicense'] = addslashes($_POST['member_bizlicense_url']);
            //包含地区数组文件
            include BasePath.DS.'data/area/areaall.php';
            $area_info = $area_array[$_POST['province_id']]['area_name'];
            $area_info .= chr(9).$area_array[$_POST['city_id']]['area_name'];
            $area_info .= chr(9).$area_array[$_POST['area_id']]['area_name'];
            $user_array['member_areainfo'] = $area_info;
            //添加会员
			$result	=  $member_id = $model_member->addMember($user_array);
			if($result) {
				//处理邀请注册 
				$invitcode = isset($_COOKIE['invitcode']) ? unserialize(base64_decode($_COOKIE['invitcode'])):'';
				if(isset($invitcode['member_id']) && $invitcode['member_id'] > 0) {
					$invitArr = array();
					$invitArr['invite_type'] = '2';
					$invitArr['member_id'] = $invitcode['member_id'];
					$invitArr['member_name'] = $invitcode['member_name'];
					$invitArr['imember_id'] =  $member_id;
					$invitArr['imember_name'] = $user_array ['member_name'];
					$invitArr['ip'] =  getIp();
					$invitArr['add_time'] = time();
					 Db::insert('member_invites', $invitArr);
					unset($invitArr , $invitcode);
					//删除cookie
					setcookie("invitcode" , '' , time()-100, '/','d1mcw.com');
					memberModel::addPredepositLog($member_id);
				}
                //注册时间标记，访问灌入垃圾用户
                setNcCookie('rp_reg',time());
                $_SESSION['is_login']	= '1';
                $_SESSION['member_id']	= $result;
                $_SESSION['member_name']= trim($user_array['member_name']);
                $_SESSION['member_email']= trim($user_array['member_email']);

                $this->mergecart();						// cookie中的cart存入数据库
                //添加会员积分
                if ($GLOBALS['setting_config']['points_isuse'] == 1){
                    $points_model =new pointsModel();
                    $points_model->savePointsLog('regist',array('pl_memberid'=>$_SESSION['member_id'],'pl_membername'=>$_SESSION['member_name']),false);
                }
				$send_msg = mobileModel::send($_POST['mobile'],'恭喜您，您的账号：'.$_POST['regName'].' 注册成功，为确保会员信息真实有效，您的账号已进入审核状态，预计48小时内审核完毕，届时便可登陆，请您耐心等待。');
				// 注册成功
                              mobileModel::send2($_POST ['mobile'],'【D1美财网】恭喜您：会员' . $_POST ['regName'] . '，您获得美财网送出的100元现金券一张，10天内使用面额为100元，10天后使用面额将变为50元，可选购精品超市海量商品，超低价，货到付款，还犹豫什么，快去挑选心仪的商品吧。现金券有效期' . date('m-d',time()) . ' - ' . date('m-d',time()+30*3600*24) . '。'); 
				mobileJump('恭喜您，您的账号：'.$_POST['regName'].' 注册成功，为确保会员信息真实有效，您的账号已进入审核状态，预计48小时内审核完毕，届时便可登陆，请您耐心等待。','index.php');
			} else {
                mobileJump('注册失败，请稍后尝试');
			}
		}
		if(C('captcha_status_register') == '1'){
			Tpl::output('nchash',substr(md5(SiteUrl.$_GET['act'].$_GET['op']),0,8));
		}
		//用户服务协议
		$model_doc	=new documentModel();
		$doc	= $model_doc->getOneByCode('agreement');
		Tpl::output('doc',$doc);
        Tpl::output('code_reg',false);   //非邀请码注册
        Tpl::output('title','邀请会员注册');   //非邀请码注册
		Tpl::output('html_title',C('site_name').' - 会员注册');
		Tpl::showpage('register');
	}
	
	//验证用户名是否存在
	public function checkNameOp(){
		$model_member	=new memberModel();
		$check_member_name	= $model_member->infoMember(array('member_name'=>trim($_GET['user_name'])));
		if(is_array($check_member_name) && count($check_member_name)>0) {
			exit('false');
		}else{
			exit('true');
		}		
	}
    //验证邀请会员是否存在,如果不存在，则返回false
    public function checkInviteNameOp(){
        $model_member	=new memberModel();
        $check_member_name	= $model_member->infoMember(array('member_name'=>trim($_GET['invite_name'])),'member_name');
        if(is_array($check_member_name) && count($check_member_name)>0) {
            exit('true');
        }else{
            exit('false');
        }
    }
	
	//手机号码检测
	public function checkMobileOp() {
			$model_member	=new memberModel();
            $check_mobile_name	= $model_member->infoMember(array('member_mobile'=>trim($_GET['mobile'])));
			if(is_array($check_mobile_name) and count($check_mobile_name)>0) {
				echo 'false';
			} else {
				echo 'true';
			}		
	}

	// 注册发送新手机验证码
    public function ajax_get_code_reg_mobileOp(){
        loginModel::sureCode();
		$model_member	=new memberModel();
        $check_mobile_name	= $model_member->infoMember(array('member_mobile'=>trim($_GET['mobile'])));
		if(is_array($check_mobile_name) and count($check_mobile_name)>0) {
			exit(json_encode(array('state'=>false,'msg'=>'手机号码已存在')));
		}
		$new_code = rand(100000, 999999);
		$mobile_member = new mobileModel();
		//存入数据库
		$array =array();
		$array['member_id'] = 0;
		$array['send_content'] ='注册发送手机验证码';	
		$array['valid_type'] =MOBILE_VALID_TYPE_REG_MEMBER;
		$array['valid_mobile'] =$_GET['mobile'];
		$array['send_code'] =md5($new_code);
		$array['valid_status'] =MOBILE_VALID_STATUS_SEND;
		$array['send_time'] =time();
		$save_code = $mobile_member->save_code($array);
		if ($save_code > 0) {
			$send_msg = mobileModel::send($_GET['mobile'], '您的注册手机验证码是：' . $new_code);
			if($send_msg > 0){
				$_SESSION['mobile_valid_id'] = $save_code;
				exit(json_encode(array('state'=>true,'msg'=>'验证码发送成功')));
			}else{
				exit(json_encode(array('state'=>false,'msg'=>'验证码发送失败')));
			}
		}else{
			exit(json_encode(array('state'=>false,'msg'=>'验证码发送失败')));
		}
    }

    /**
     * 注册验证手机验证码
     */
    public function ajax_check_mobcodeOp()
    {
        $sql = "SELECT * FROM #__member_mobile_validation WHERE valid_id = '{$_SESSION['mobile_valid_id']}'";
        $mobile_valid_info = Db::queryRow($sql);
        $nowTime = time();
        //核对验证码期限
        if($nowTime > ($mobile_valid_info['send_time']+(MOBILE_VALID_ACTIVE_TERM * 60))){
            exit('false');
        }
        if($mobile_valid_info['send_code'] != md5($_GET["mobileCode"])){
            exit('false');
        }
        exit('true');
    }
	//ajax验证邀请码有效性
	public function checkCodeOp(){
		$code = trim($_GET['code']);
		//查询该邀请码是否已使用
		$sql = "SELECT * FROM #__member WHERE InvitationCode = '$code'";
		$m_rs = Db::queryRow($sql);
		if(!empty($m_rs) && is_array($m_rs)){
			exit('false');
		}else{
			//查询是否存在该邀请码
			$sql = "SELECT * FROM #__ams_store WHERE invitation_code = '$code'";
			$a_rs = Db::queryRow($sql);
			if(!empty($a_rs) && is_array($a_rs)){
				exit('true');
			}else{
				//查询是否存在该邀请码
				$sql = "SELECT * FROM #__ams_supplier WHERE invitation_code = '$code'";
				$s_rs = Db::queryRow($sql);
				if(!empty($s_rs) && is_array($s_rs)){
					exit('true');
				}else{
					exit('false');
				}
			}
		}
	}

	//上传图片
	public function upload_imageOp()
	{
		//提交
		$input_name = $_GET['input_name'];
		$document_root = $_SERVER['DOCUMENT_ROOT'];
		$path = "/upload/member/";
		if (!file_exists('/upload/member')) {
			mkdir('/upload/member', 0777);
		}
		if(empty($_FILES[$input_name]['name'])){
			$arr['status'] = 'error';
		}else {
			$tmp_ext = explode(".", $_FILES[$input_name]['name']);
			$file_type = $tmp_ext [count($tmp_ext) - 1];
			$file_name = md5(time());
			$file_path = $document_root . $path . $file_name . '.' . $file_type;
			$file_type_array = array('jpg', 'jpeg', 'gif', 'png');
			if (!in_array($file_type, $file_type_array)) {
				$arr['status'] = 'error';
			} else {
				$upload = @move_uploaded_file($_FILES[$input_name]['tmp_name'], $file_path);
				if ($upload === FALSE) {
					$arr['status'] = 'error';
				}
			}
			$arr['file_path'] = $path . $file_name . '.' . $file_type;
			$arr['status'] = 'ok';
		}
		echo json_encode($arr);
	}
	
	 //产生随机店名后缀
	private function create_random($store_name){
        $name = null;
        while (true) {
			$num = range('0','9');
			shuffle($num);//打乱数组
			$key = array_rand($num,3);//随机取3个单元元素
			$str = '';
			foreach($key as $v){
				$str .= $num[$v];
			}
			$name = $store_name.'_'.$str;
            $sql = "SELECT * FROM #__member WHERE member_name = '$name'";
            if (!db::queryRow($sql)) {
                break;
            }else{
                sleep(1);
            }
        }
        return $name;
    }
    //手机端验证类型判断,选择哪种注册方案就用对哪种照片进行验证
    private function mv_type($type){
        if($type==$_POST['mv_type']){
            return true;
        }
        return false;
    }

}